﻿//https://leetcode.cn/problems/design-circular-queue/?envType=problem-list-v2&envId=queue&difficulty=MEDIUM

class MyCircularQueue {
private:
    int front;
    int rear;
    int capacity;
    vector<int> v;
public:
    MyCircularQueue(int k) {
        this->capacity = k + 1;
        this->v = vector<int>(capacity);
        rear = front = 0;
    }

    bool enQueue(int value) {
        if (isFull())
        {
            return false;
        }
        v[rear] = value;
        rear = (rear + 1) % capacity;
        return true;

    }

    bool deQueue() {
        if (isEmpty())
        {
            return false;
        }
        front = (front + 1) % capacity;
        return true;
    }

    int Front() {
        if (isEmpty()) {
            return -1;
        }
        return v[front];
    }

    int Rear() {
        if (isEmpty()) {
            return -1;
        }
        return v[(rear - 1 + capacity) % capacity];
    }

    bool isEmpty() {
        return rear == front;
    }

    bool isFull() {
        return ((rear + 1) % capacity) == front;
    }
};
